<template>
  <div>
    <h1>当前的值{{ $store.state.count }} - {{ $store.getters.judge }}</h1>
    <input type="text" v-model.number="val">
    <button @click="handleIncr">+</button>
    <button @click="handleDecr">-</button>
    <button @click="handleAsync">延迟1秒加</button>
  </div>
</template>
<script>
export default {
  name: "App",
  data() { 
    return {
      val:1
    }
  },
  methods: {
    handleIncr() { 
      if (!this.val) { 
        return alert("请输入数值");
      }
      if (isNaN(this.val)) {
        this.val = "";
        return alert("输入值不是数字");
      }
      this.$store.dispatch("increment",this.val);
    },
    handleDecr() { 
      if (!this.val) {
        return alert("请输入数值");
      }
      this.$store.dispatch("decrement",this.val);
    },
    handleAsync() { 
      if (!this.val) {
        return alert("请输入数值");
      }
      this.$store.dispatch("incrAsync",this.val);
    }
  }
}
</script>
<style>

</style>